$(function () {
    let form = layui.form
    form.verify({
        nickname: [
            /^[\S]{1,10}$/,
            '请输入1到10位非空字符'
        ]
    })
    initUserInfo()
    function initUserInfo() {
        axios({
            url:'/my/userinfo',
            method:'get',
        }).then(res=>{
            //成功回调
            // console.log(res)
            if (res.data.status != 0) {
                return layer.msg(res.data.message)
            }
            form.val('formUserInfo',res.data.data)
        });
    }
    $('#btnReset').on('click', function (e) {
        e.preventDefault()
        initUserInfo()
    })
    $('form').on('submit', function (e) {
        e.preventDefault()
        axios({
            url:'/my/userinfo',
            method:'post',
            data: $(this).serialize(),
        }).then(res=>{
            //成功回调
            console.log(res);
            if (res.data.status != 0) {
                return layer.msg(res.data.message)
            }
            layer.msg('恭喜你修改成功')
            window.parent.gitUserInfo()
        });
    })
})